﻿
namespace TLang.Values
{
    public class Type
    {

        public static bool subtype(Value type1, Value type2, bool ret)
        {
            if (!ret && type2 is AnyType) {
                return true;
            }

            if (type1 is UnionType) {
                foreach (Value t in ((UnionType)type1).values)
                {
                    if (!subtype(t, type2, false))
                    {
                        return false;
                    }
                }
                return true;
            } else if (type2 is UnionType) {
                return ((UnionType)type2).values.Contains(type1);
            } else {
                return type1.Equals(type2);
            }
        }


        public static readonly Value BOOL = new BoolType();
        public static readonly Value INT = new IntType();
        public static readonly Value STRING = new StringType();
    }
}
